package com.ruoyi.team.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.team.mapper.ContractMapper;
import com.ruoyi.team.domain.Contract;
import com.ruoyi.team.service.IContractService;

import javax.annotation.Resource;

/**
 * 合同信息Service业务层处理
 *
 * @author Judy
 * @date 2022-11-28
 */
@Service
public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> implements IContractService {
    @Autowired
    private ISysUserService userService;
    @Resource
    private ContractMapper contractMapper;
    /**
     * 查询合同信息列表
     *
     * @param contract 合同信息
     * @return 合同信息
     */
    @Override
    public List<Contract> selectContractList(Contract contract) {
        List<Contract> contracts = getBaseMapper().selectContractList(contract);
        for (Contract con : contracts) {
            SysUser sysUser = userService.selectUserById(con.getInputUser());
            con.setInputUserName(sysUser.getUserName());
        }
        return contracts;
    }

    @Override
    public int updateStatus(Long id) {
        return contractMapper.updateStatus(id);
    }

    @Override
    public int updateAff(Long id) {
        return contractMapper.updateAff(id);
    }

    @Override
    public int updatePass(Long id) {
        return contractMapper.updatePass(id);
    }

    @Override
    public int updateNoPass(Long id) {
        return contractMapper.updateNoPass(id);
    }


    @Override
    public boolean save(Contract entity) {
        LoginUser user = SecurityUtils.getLoginUser();
        entity.setInputUser(user.getUserId());
        entity.setInputTime(new Date());
        entity.setAffixSealState(0);
        entity.setAuditState(0);
        entity.setNullifyState(0);
        return super.save(entity);
    }
}
